package com.ctyon.watchmanager.model.db.entity;

import com.ctyon.common.util.DataUtil;
import com.ctyon.watchmanager.model.db.entity.ex.ChatMessage;
import com.ctyon.watchmanager.util.BytesUtil;

import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.Ignore;
import androidx.room.PrimaryKey;

/**
 * CreateDate：19-7-2 on 下午8:08
 * Describe:
 * Coder: lee
 */
@Entity(tableName = "chatMessage")
public class ChatMessageEntity implements ChatMessage {

    @PrimaryKey(autoGenerate = true)
    private int id;

    @ColumnInfo(name = "in_msg")
    private boolean inMsg;

    @ColumnInfo(name = "msg_nick")
    private String msgNick;

    @ColumnInfo(name = "msg_content")
    private String msgContent;

    @ColumnInfo(name = "msg_type")
    private int msgType;

    @ColumnInfo(name = "msg_time")
    private long msgTime;

    public ChatMessageEntity() {
    }

    @Ignore
    public ChatMessageEntity(String msgType,String msgNick, byte[] data, boolean inMsg) {
        if (msgType.equals("text")){
            this.msgType = 0;
            this.msgContent = DataUtil.unicode2String(new String(data));
        } else if (msgType.equals("audio")){
            this.msgType = 1;
            this.msgContent = BytesUtil.unpackData(0, data);
        }
        this.msgNick = msgNick;
        this.inMsg = inMsg;
        this.msgTime = System.currentTimeMillis();
    }

    @Ignore
    public ChatMessageEntity(int msgType, String msgContent, boolean inMsg) {
        this.msgType = msgType;
        this.msgContent = msgContent;
        this.inMsg = inMsg;
        this.msgTime = System.currentTimeMillis();
    }

    @Override
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Override
    public boolean isInMsg() {
        return inMsg;
    }

    public void setInMsg(boolean inMsg) {
        this.inMsg = inMsg;
    }

    @Override
    public String getMsgContent() {
        return msgContent;
    }

    public void setMsgContent(String msgContent) {
        this.msgContent = msgContent;
    }

    @Override
    public int getMsgType() {
        return msgType;
    }

    public void setMsgType(int msgType) {
        this.msgType = msgType;
    }

    @Override
    public long getMsgTime() {
        return msgTime;
    }

    public void setMsgTime(long msgTime) {
        this.msgTime = msgTime;
    }

    public String getMsgNick() {
        return msgNick;
    }

    public void setMsgNick(String msgNick) {
        this.msgNick = msgNick;
    }

    @Override
    public String toString() {
        return "ChatMessageEntity{" +
                "id=" + id +
                ", inMsg=" + inMsg +
                ", msgNick='" + msgNick + '\'' +
                ", msgContent='" + msgContent + '\'' +
                ", msgType=" + msgType +
                ", msgTime=" + msgTime +
                '}';
    }
}
